package com.distribution.common.web.config;

import com.distribution.common.web.filter.WebFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * @author test
 * @date 2022年01月03日 22:57
 */

@Configuration
public class FilterConfig {

    /**
     * 注入crosFilter
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean registerWebFilter(WebFilter webFilter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(webFilter);
        registration.addUrlPatterns("/*");
        registration.setName("crosFilter");

        //设置优先级别
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
}
